package main

import (
	"fmt"
	"time"

	"github.com/henrylee2cn/faygo"
)

type Index struct {
	Id        int      `param:"<in:path> <required> <desc:ID> <range: 0:10>"`
	Title     string   `param:"<in:query> <nonzero>"`
	Paragraph []string `param:"<in:query> <name:p> <len: 1:10> <regexp: ^[\\w]*$>"`
	Cookie    string   `param:"<in:cookie> <name:faygoID>"`
}

func (t *Index) Serve(ctx *faygo.Context) error {

	if ctx.CookieParam("faygoID") == "" {
		ctx.SetCookie("faygoID", time.Now().String())
	}
	return ctx.JSON(200, t)
}
func rest_api() {

	app := faygo.New("myapp", "0.1")

	app.GET("/index/:id", new(Index))

	fmt.Printf("faygo start ----------------------------------------\n")

	faygo.Run()

}
